cssmatcher: Use widget path's state
authorBenjamin Otte <otte@redhat.com>
Sat, 19 Jul 2014 21:26:12 +0000 (23:26 +0200)
committerBenjamin Otte <otte@redhat.com>
Sat, 19 Jul 2014 21:42:39 +0000 (23:42 +0200)
Don't take a state when constructing the CSS matcher. Instead, rely on
the newly introduced state in the widget path.

This way, the state can be queried not only on the first element, but on
all elements of the widget path.

gtk/gtkcssmatcher.c
gtk/gtkcssmatcherprivate.h
gtk/gtkcssprovider.c
gtk/gtkstylecontext.c

index 04d4571ce18a21b0f265c3e839e49f22133a0178..d169c274cf33042ab5dc0ba93ead37245bcba31c 100644 (file)
@@ -32,7 +32,6 @@ gtk_css_matcher_widget_path_get_parent (GtkCssMatcher       *matcher,
 
   matcher->path.klass = child->path.klass;
   matcher->path.path = child->path.path;
-  matcher->path.state_flags = 0;
   matcher->path.index = child->path.index - 1;
   matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index);
 
@@ -48,7 +47,6 @@ gtk_css_matcher_widget_path_get_previous (GtkCssMatcher       *matcher,
 
   matcher->path.klass = next->path.klass;
   matcher->path.path = next->path.path;
-  matcher->path.state_flags = 0;
   matcher->path.index = next->path.index;
   matcher->path.sibling_index = next->path.sibling_index - 1;
 
@@ -58,7 +56,7 @@ gtk_css_matcher_widget_path_get_previous (GtkCssMatcher       *matcher,
 static GtkStateFlags
 gtk_css_matcher_widget_path_get_state (const GtkCssMatcher *matcher)
 {
-  return matcher->path.state_flags;
+  return gtk_widget_path_iter_get_state (matcher->path.path, matcher->path.index);
 }
 
 static gboolean
@@ -192,15 +190,13 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_WIDGET_PATH = {
 
 gboolean
 _gtk_css_matcher_init (GtkCssMatcher       *matcher,
-                       const GtkWidgetPath *path,
-                       GtkStateFlags        state)
+                       const GtkWidgetPath *path)
 {
   if (gtk_widget_path_length (path) == 0)
     return FALSE;
 
   matcher->path.klass = &GTK_CSS_MATCHER_WIDGET_PATH;
   matcher->path.path = path;
-  matcher->path.state_flags = state;
   matcher->path.index = gtk_widget_path_length (path) - 1;
   matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (path, matcher->path.index);
 
index 1b2108c3870b5f9ef04c830f4eaa89c6a7b7766f..a98807180ac92e0e62402be575e442b8f6e8ab4b 100644 (file)
@@ -56,7 +56,6 @@ struct _GtkCssMatcherClass {
 struct _GtkCssMatcherWidgetPath {
   const GtkCssMatcherClass *klass;
   const GtkWidgetPath      *path;
-  GtkStateFlags             state_flags;
   guint                     index;
   guint                     sibling_index;
 };
@@ -74,8 +73,7 @@ union _GtkCssMatcher {
 };
 
 gboolean          _gtk_css_matcher_init           (GtkCssMatcher          *matcher,
-                                                   const GtkWidgetPath    *path,
-                                                   GtkStateFlags           state) G_GNUC_WARN_UNUSED_RESULT;
+                                                   const GtkWidgetPath    *path) G_GNUC_WARN_UNUSED_RESULT;
 void              _gtk_css_matcher_any_init       (GtkCssMatcher          *matcher);
 void              _gtk_css_matcher_superset_init  (GtkCssMatcher          *matcher,
                                                    const GtkCssMatcher    *subset,
index c8e76ff74b1ba2576ae9129d70446ac12d265555..429713b3632db8d20cb3972b6b3e9a3cf79af0c6 100644 (file)
@@ -40,6 +40,7 @@
 #include "gtkstylepropertiesprivate.h"
 #include "gtkstylepropertyprivate.h"
 #include "gtkstyleproviderprivate.h"
+#include "gtkwidgetpath.h"
 #include "gtkbindings.h"
 #include "gtkmarshalers.h"
 #include "gtkprivate.h"
@@ -1668,8 +1669,21 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
   gchar *prop_name;
   gint i;
 
-  if (!_gtk_css_matcher_init (&matcher, path, state))
-    return FALSE;
+  if (state == gtk_widget_path_iter_get_state (path, -1))
+    {
+      gtk_widget_path_ref (path);
+    }
+  else
+    {
+      path = gtk_widget_path_copy (path);
+      gtk_widget_path_iter_set_state (path, -1, state);
+    }
+
+  if (!_gtk_css_matcher_init (&matcher, path))
+    {
+      gtk_widget_path_unref (path);
+      return FALSE;
+    }
 
   tree_rules = _gtk_css_selector_tree_match_all (priv->tree, &matcher);
   verify_tree_match_results (css_provider, &matcher, tree_rules);
@@ -1712,6 +1726,7 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
 
   g_free (prop_name);
   g_ptr_array_free (tree_rules, TRUE);
+  gtk_widget_path_unref (path);
 
   return found;
 }
index 3d1e78876e3f3fee56a219dee1c05c5a23db5c56..cc04eea70f19f0f755eed332701c58770845d4be 100644 (file)
@@ -748,8 +748,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
     }
 
   /* Set widget state */
-  gtk_widget_path_iter_set_state (path, pos,
-                                  gtk_widget_path_iter_get_state (path, pos) | info->state_flags);
+  gtk_widget_path_iter_set_state (path, pos, info->state_flags);
 
   return path;
 }
@@ -770,7 +769,7 @@ build_properties (GtkStyleContext      *context,
   path = create_query_path (context, info);
   lookup = _gtk_css_lookup_new (relevant_changes);
 
-  if (_gtk_css_matcher_init (&matcher, path, info->state_flags))
+  if (_gtk_css_matcher_init (&matcher, path))
     _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
                                         &matcher,
                                         lookup);
@@ -2957,7 +2956,7 @@ gtk_style_context_needs_full_revalidate (GtkStyleContext  *context,
           GtkCssMatcher matcher, superset;
 
           path = create_query_path (context, priv->info);
-          if (_gtk_css_matcher_init (&matcher, path, priv->info->state_flags))
+          if (_gtk_css_matcher_init (&matcher, path))
             {
               _gtk_css_matcher_superset_init (&superset, &matcher, GTK_STYLE_CONTEXT_RADICAL_CHANGE & ~GTK_CSS_CHANGE_SOURCE);
               priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),